package com.ccp.dev.form.service;

import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.core.util.encrypt.EncryptUtil;
import org.springframework.stereotype.Service;

/**
 * 字段加密解密service
 * @author zhaowj
 */
@Service
public class FormFieldEncryptService {

    /**
     * 加密某一字段
     *
     * @param fieldValue
     * @return
     */
    public String encryptField(String fieldValue) {
        try {
            if (StringUtil.isNotEmpty(fieldValue)) {
                fieldValue = EncryptUtil.encrypt(fieldValue);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return fieldValue;
    }

    /**
     * 解密某一字段
     *
     * @param fieldValue
     * @return
     */
    public String decryptField(String fieldValue) {
        try {
            if (StringUtil.isNotEmpty(fieldValue)) {
                fieldValue = EncryptUtil.decrypt(fieldValue);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return fieldValue;
    }
}
